package com.share.finance.risk.third.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.share.common.common.Page;
import com.share.finance.risk.third.mapper.ThirdRequestLogMapper;
import com.share.finance.risk.third.model.db.ThirdRequestLog;
import com.share.finance.risk.third.model.vo.ThirdLogPageReq;
import com.share.finance.risk.third.service.IThirdRequestLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class ThirdRequestLogServiceImpl extends ServiceImpl<ThirdRequestLogMapper, ThirdRequestLog> implements IThirdRequestLogService {

    @Resource
    private ThirdRequestLogMapper thirdRequestLogMapper;

    @Override
    public Page pageList(ThirdLogPageReq req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        LambdaQueryWrapper<ThirdRequestLog> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(req.getReqIp())) {
            queryWrapper.like(ThirdRequestLog::getReqIp, req.getReqIp());
        }
        if (StringUtils.isNotBlank(req.getExeIp())) {
            queryWrapper.like(ThirdRequestLog::getExeIp, req.getExeIp());
        }
        if (StringUtils.isNotBlank(req.getIntIds())) {
            queryWrapper.like(ThirdRequestLog::getIntIds, req.getIntIds());
        }
        if (StringUtils.isNotBlank(req.getProductCode())) {
            queryWrapper.like(ThirdRequestLog::getProductCode, req.getProductCode());
        }
        if (StringUtils.isNotBlank(req.getRequestData())) {
            queryWrapper.like(ThirdRequestLog::getRequestData, req.getRequestData());
        }
        if (StringUtils.isNotBlank(req.getResponseData())) {
            queryWrapper.like(ThirdRequestLog::getResponseData, req.getResponseData());
        }
        queryWrapper.orderByDesc(ThirdRequestLog::getId);
        List<ThirdRequestLog> list = thirdRequestLogMapper.selectList(queryWrapper);
        return new Page<>(list, new PageInfo<>(list).getTotal(), req);
    }
}
